import {useEffect, useState} from "react";

import {RespSysSettingDataType, getAllSysPostList, getAllSysRoleList, getOrgTreeSelect} from "@/components/app/commonSystemSetting/api";

interface InitData{
    sysPostList: {label: string;value:number;}[];
    sysRoleList: {label: string;value:number;}[];
    orgTreeSelectData: RespSysSettingDataType.TreeSelectData[];
}

export const useCreateUser = () => {
    const [loading, setLoading] = useState<boolean>(true);
    const [initData, setInitData] = useState<InitData>({sysPostList: [], sysRoleList: [], orgTreeSelectData: []});

    useEffect(() => {
        setLoading(true);
        Promise.all([getAllSysPostList(), getAllSysRoleList() , getOrgTreeSelect()]).then((resp) => {
            const [sysPostResp, sysRoleResp, orgResp] = resp;
            setInitData({
                sysRoleList:(sysRoleResp.data || []).map(item => ({label: item.roleName, value: item.roleId})),
                sysPostList:(sysPostResp.data || []).map(item => ({label: item.postName, value: item.postId})),
                orgTreeSelectData: orgResp.data,
            })
            setLoading(false);
        });
    }, []);

    return { loading, initData }
}
